package org.example.myleet.p830;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Solution {
    /**
     * 1 ms
     */
    public List<List<Integer>> largeGroupPositions(String s) {
        List<List<Integer>> result = new ArrayList<>();
        int start = 0, count = 1;
        char c = s.charAt(0);
        for (int i=1; i<s.length(); i++) {
            char c_ = s.charAt(i);
            if (c == c_) {
                ++count;
            } else {
                if (count >= 3) {
                    result.add(Arrays.asList(start, i-1));
                }
                count = 1;
                start = i;
                c = c_;
            }
        }
        if (count >= 3) {
            result.add(Arrays.asList(start, s.length()-1));
        }
        return result;
    }
}
